package com.skywolf.chem.manager.controller;

import com.skywolf.chem.comments.entity.CommentInfo;
import com.skywolf.chem.comments.pojo.CommentApprovalParam;
import com.skywolf.chem.comments.pojo.CommentQueryParam;
import com.skywolf.chem.comments.service.ICommentInfoService;
import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.common.sysconfig.response.RespData;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by pei_pei on 2020/6/29.
 */
@RestController
@RequestMapping("/manager/comment")
public class CommentManagerController {

    @Autowired
    ICommentInfoService commentInfoService;

    @ApiOperation(value = "评论列表",notes = "评论列表")
    @RequestMapping(value = "/getComments",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<CommentInfo> getComments(@RequestBody @Validated CommentQueryParam queryParam) {
        PageVO<CommentInfo> page = commentInfoService.managerCommentList(queryParam);
        return RespData.success(page);
    }

    @ApiOperation(value = "审核评论;0-待审批 1-通过 2-不通过",notes = "审核评论：0-待审批 1-通过 2-不通过")
    @RequestMapping(value = "/approvalComments",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<String> approvalComments(@RequestBody @Validated CommentApprovalParam commentApprovalParam) {
        CommentInfo info = new CommentInfo();
        info.setId(commentApprovalParam.getId());
        info.setCommentStatus(commentApprovalParam.getStatus());
        if(StringUtils.isNotBlank(commentApprovalParam.getApproveStr())){
            info.setApproveStr(commentApprovalParam.getApproveStr());
        }
        commentInfoService.updateById(info);
        return RespData.success("success");
    }


}
